package org.holynite.fieldmanage.entities

import javax.persistence.*
import java.sql.Timestamp

/**
 * Created by midnite on 15/1/4.
 */
@Entity
@Table(name = "consume_record")
class ConsumeRecord implements Serializable {
	@Id
	@Column(name = "serial", nullable = false)
	String serialNumber
	@Column(name = "operator")
	String operatorId
	@Transient
	Administrator operator
	@Column(name = "customer")
	String customerId
	@Transient
	Customer customer
	@Column(name = "field")
	String fieldId
	@Transient
	Field field
	@Column(name = "scheme")
	String schemeId
	@Transient
	ChargeScheme scheme
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "opened", nullable = false)
	Date openTime
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "closed", nullable = false)
	Date closeTime
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "etc")
	Date estimateToClose
	@Column(name = "is_closed", nullable = false)
	Boolean closed = false
	@Column(name = "consumed", nullable = false)
	Float consumed = 0

	boolean equals(o) {
		if (this.is(o)) return true
		if (getClass() != o.class) return false

		ConsumeRecord that = (ConsumeRecord) o

		if (serialNumber != that.serialNumber) return false

		return true
	}

	int hashCode() {
		return (serialNumber != null ? serialNumber.hashCode() : 0)
	}
}
